<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .aui-searchbar-input {
            width: 98% !important;
        }
    </style>
</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;">
        <a class="aui-pull-left aui-btn" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle" style="font-size: 0.8rem;">
            <span>单号:</span><span id="titleVal"></span>
        </div>
        <!-- <button class="aui-btn oranger" style="float:right;  font-size: 0.9rem;" onclick="save();">确认</button> -->
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:0px;">
        <!-- <ul class="aui-list aui-form-list">
        <li class="aui-list-item"> -->
        <!-- <div class="aui-list-item-inner">
                <div class="aui-list-item-label">仓库</div>
                <div class="aui-list-item-input"> -->
        <!-- <input type="text" placeholder="选择/扫描 仓库" id="workCenterCode" value="" onclick="getIdSelector();" /> -->
        <!-- </div>
                <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCenter()"></i>
            </div> -->
        <!-- </li>
    </ul> -->
        <div class="aui-searchbar" id="search" style=" margin-top: 50px;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <!-- <form> -->
                        <input type="search" placeholder="请扫描库位" id="cellCode" onclick="getIdSelector();">
                    <!-- </form> -->
                </div>
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4"
                onclick="goSelectWorkCell()">选择</div>
        </div>
        <div class="aui-searchbar" id="search" style="position: relative;  margin-top: 90px;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <!-- <input type="search" placeholder="请扫描" id="codeBar" onclick="getIdSelector();" > -->
                    <!-- <input type="text" placeholder="选择/扫描 仓库" id="codeBar" value="" onclick="getIdSelector();" /> -->
                    <input type="text" placeholder="请扫描物料条码" id="codeBar" value="" onclick="getIdSelector();" />
                </div>
            </div>

        </div>
    </div>
    <ul class="ui-selectee" id="tbodyHtml"
        style="margin-bottom: 40px;margin-top: 0px; background-color:rgb(127, 194, 27);">

        <!-- <li class='sortable ui-selectee ui-sortable'>
            <ul class='aui-list aui-media-list ui-selectee'>
                <li class='aui-list-item ui-selectee'>
                    <div class='aui-media-list-item-inner ui-selectee'>
                        <div class='aui-list-item-inner ui-selectee'>
                            <div class='aui-list-item-text ui-selectee' style='height: 22px;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title'>库位编码</div>
                                <div class='aui-list-item-inner ui-selectee'>LT01-01</div>
                            </div>
                            <div class='aui-list-item-text ui-selectee' style='height: 22px;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title'>库位名称</div>
                                <div class='aui-list-item-inner ui-selectee'>轮胎-01库位</div>
                            </div>
                            <div class='aui-list-item-text ui-selectee' style='height: 22px;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title'>物料编码</div>
                                <div class='aui-list-item-inner ui-selectee'>2810010-BQ01</div>
                            </div>
                            <div class='aui-list-item-text ui-selectee' style='height: 22px;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title'>物料名称</div>
                                <div class='aui-list-item-inner ui-selectee'>前副车架总成-D058-D058</div>
                            </div>
                            <div class='aui-list-item-text ui-selectee' style='height: 22px;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title'>批次号</div>
                                <div class='aui-list-item-inner ui-selectee'>2021031301</div>
                            </div>
                            <div class='aui-list-item-text ui-selectee' style='height: 22px;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title'>库存数量</div>
                                <div class='aui-list-item-inner ui-selectee'>1</div>
                            </div>
                            <div class='aui-list-item-text ui-selectee' style='height: 22px;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title'>盘点数量</div>
                                <div class='aui-list-item-inner ui-selectee'>33</div>
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
        </li> -->

    </ul>

    <div>
        <div style="height:60px;"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var listData;
    var idSelector = "";//光标所在id
    var scanRule = ""; //条码解析规则

    var workCellGid = "";
    var workCellCode = "";
    var workCellName = "";

    //初始化查询仓库下拉框
    apiready = function () {
        $("#codeBar").focus();
        idSelector = "codeBar";
        listData = [];
        $api.html($api.byId("titleVal"), api.pageParam.code);
        doSearch(api.pageParam.sysid);

        //查询条码解析规则
        initScanRule();
    }

    //查询扫描规则
    function initScanRule() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getTmScanRule";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    scanRule = myobj.scanRule
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //查询
    function doSearch(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/wminventorybillDetailList";
        var data = {
            values: {
                key: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    listData = list;
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        // console.log(i + "sysid", list[i].sysid);
                        html += "<li class='sortable ui-selectee ui-sortable'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item  ui-selectee'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        //   html += "<div class='aui-list-item-inner ui-selectee' >";
                        var listex = list[i].qty == null || list[i].qty == "" ? 0 : list[i].qty;
                        if (listex != 0) {
                            html += "<div class='aui-list-item-inner ui-selectee' style=' background-color:rgb(127, 194, 27);'>";
                        } else {
                            html += "<div class='aui-list-item-inner ui-selectee' >";
                        }
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 22px; '>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>库位编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'> <font size = \"4\">" + list[i].work_cell_code + "</font></div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 22px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>库位名称</div>";
                        //      html += "<div class='aui-list-item-inner ui-selectee'> <font size = \"4\">" + list[i].work_cell_name + "</font></div>";
                        html += "<div class='aui-list-item-inner ui-selectee'> <font size = \"4\">" + list[i].workcellname + "</font></div>";

                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].mrl_code + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名称</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].mrl_name + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>批次号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].lot_code + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>库存数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].stock_qty + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>盘点数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' id='" + list[i].sysid + "'>" + (list[i].qty == null || list[i].qty == "" ? 0 : list[i].qty) + "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                    $("#codeBar").focus();
                    idSelector = "codeBar";
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            // checkData();
            if (idSelector == 'cellCode') {

                $("#cellCode").val(ret);
                getWorkCell(ret, "cellCode");
            } else if (idSelector == 'codeBar') {

                tmSplit(ret);

            }
        });
    }

    //3；PDA自带扫描回车事件-库位
    $("#cellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var cellCode = $(this).val();
        if (keycode == '13') {
            //库位编码
            $("#cellCode").val(cellCode);
            //校验库位编码是否对应
            getWorkCell(cellCode, "cellCode");
        }
    });
    //5:库位扫描校验
    function getWorkCell(code, inputId) {

        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: {
                flag: "in_rk", //库内库间标识（out_kn库内  out_kj库间,in_rk入库出库）
                workCenterGid: api.pageParam.work_center_id, //仓库GID
                workCellCode: code, //库位编码
                relWorkCellGid: "", //调入库位
                tm: "",
                workCellFlag: "", //原库位调入库位flag
                un: un

            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    workCellGid = list[0].workCellGid;
                    workCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                    workCellName = list[0].workCellName;
                    document.getElementById(inputId).value = workCellCode;
                    $("#codeBar").focus();
                    idSelector = "codeBar";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#" + inputId).focus();
                    $("#" + inputId).select();
                }
            }
        });
    }
    //3；PDA自带扫描回车事件
    $("#codeBar").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {
            //仓库编码
            // setQTY();
            // checkData();
            // $("#e5d86397fc0940bfa680d70ae124b5e6").val(78);
            //tmSplit(sm);
            if(sm != null && sm != "" && sm != undefined){
                console.log(sm)
                $("#codeBar").blur();
                //调用条码解析+保存事件
                tmSplit(sm);
            }
        }
    });


    //扫描之后条码解析
    function tmSplit(sm) {
        $("#codeBar").val(sm);
        //直接解析
        if (scanRule == "old") {

            //本地解析
            localAnalyze(sm);

        } else {

            //后台解析
            postAnalyze(sm);
        }
    }

    //本地解析
    function localAnalyze(sm) {
        var arr = sm.split(",");
        var mrlCode = arr[1];
        var qty = arr[2];
        var lotCode = arr[3]
        checkData(mrlCode, qty, lotCode);
    }

    //后台解析条码
    function postAnalyze(sm) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/analysisBarCodeCommon";
        var data = {
            values: {
                tm: sm, //条码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    var map = myobj.data;
                    var mrlCode = map['mrlCode'];
                    var qty = map['qty'];
                    var lotCode = map['lotCode'];
                    checkData(mrlCode, qty, lotCode);
                } else if (myobj.code == '1') {

                    $("#codeBar").val("");
                    $("#codeBar").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                //alert(JSON.stringify(err));
                alert("连接超时，请耐心等待");
            }
        });
    }


    function setQTY() {
        var codeBar = $("#codeBar").val();
        if (codeBar == null || codeBar == "") {
            return;
        }
        var cellCode = $("#cellCode").val();
        //解析出条码中的 物料、批次 进行匹配明细
        //YDGYS-A,2810010-BQ01,2,2021031301,e7e26a1af372470987d7c5acb0040547,,,,,B-20210807-1918
        //供应商编码，物料编码，数量，批次号，不知道，，，，，不知道
        console.log("dd4444444444", cellCode);
        console.log("条码", codeBar);
        var arr = codeBar.split(",");
        var mrlCode = arr[1];
        var lotCode = arr[3];
        var qqt = arr[2];
        console.log("条码ss", JSON.stringify(arr));
        console.log("条码解析", mrlCode, lotCode, qqt);
        for (var i = 0; i < listData.length; i++) {
            console.log(i + "物料编码", listData[i].mrl_code);
            console.log(i + "批次号", listData[i].lot_code);
            if (listData[i].mrl_code == mrlCode && listData[i].lot_code == lotCode) {
                console.log(i + "判断", cellCode != null && cellCode != undefined && cellCode != "");
                if (cellCode != null && cellCode != undefined && cellCode != "") {
                    console.log(i + "库位", listData[i].work_cell_code);
                    if (listData[i].work_cell_code == cellCode) {
                        listData[i].qty = listData[i].qty == "" || listData[i].qty == null ? qqt : (parseInt(listData[i].qty) + parseInt(qqt));
                    }
                } else {
                    console.log(i + "库位rr", listData[i].work_cell_code);
                    listData[i].qty = listData[i].qty == "" || listData[i].qty == null ? qqt : (parseInt(listData[i].qty) + parseInt(qqt));
                }
            }
        }
        // console.log("结果",JSON.stringify(listData));
        creatwHtml(listData);
    }

    function creatwHtml(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            var qty = list[i].qty == null || list[i].qty == "" ? 0 : list[i].qty;
            html += "<li class='sortable ui-selectee ui-sortable'>";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item  ui-selectee'>";
            html += "<div class='aui-media-list-item-inner ui-selectee' style='background-color:red;'>";
            html += "<div class='aui-list-item-inner ui-selectee' style='background-color:red;'>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title' style='background-color:red;'>库位编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].work_cell_code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'  style='height: 22px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>库位名称</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].work_cell_name + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].mrl_code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名称</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].mrl_name + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>批次号</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].lot_code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>库存数量</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].stock_qty + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 22px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>盘点数量</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + (list[i].qty == null || list[i].qty == "" ? 0 : list[i].qty) + "</div>";
            html += "</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        console.log("htmlllll")
        // $api.html($api.byId("tbodyHtml"), "");
        // $api.append($api.byId("tbodyHtml"),  "");
        // $api.dom('#tbodyHtml').innerHTML = html;
        $api.html($api.byId("tbodyHtml"), html);
        //api.parseTapmode();//api.hideProgress();

    }
    //6：选择库位
    function goSelectWorkCell() {
        api.openWin({
            name: 'uwmSelectWorkCell',
            url: 'uwmSelectWorkCell.html',
            pageParam: {
                flag: "in_rk",
                name: "uwmInventoryTaskDetail",
                tm: '',
                workCenterGid: api.pageParam.work_center_id,
                relWorkCellGid: "",
                workCellFlag: ""
            }
        });
    }
    //库位选择后回调函数
    function setWorkCell(id, code, name) {
        workCellGid = id;
        workCellCode = code;
        workCellName = name;
        document.getElementById('cellCode').value = code + ":" + name;
        $("#codeBar").focus();
        var e = "codeBar";
        idSelector = e;
    }

    //保存按钮
    function checkData(mrlCode, qqt, lotCode) {
        var codeBar = $("#codeBar").val();
        if (codeBar == null || codeBar == "") {
            return;
        }
        var cellCode = $("#cellCode").val();
        //解析出条码中的 物料、批次 进行匹配明细
        //YDGYS-A,2810010-BQ01,2,2021031301,e7e26a1af372470987d7c5acb0040547,,,,,B-20210807-1918
        //供应商编码，物料编码，数量，批次号，不知道，，，，，不知道
        // var arr = codeBar.split(",");
        // if (arr.length < 4) {
        //     api.toast({
        //         msg: '条码长度不匹配！',
        //         duration: 3000
        //     });
        //     return;
        // }
        // var mrlCode = arr[1];
        // var lotCode = arr[3];
        // var qqt = arr[2];
        var flag = false;
        if (mrlCode == null || mrlCode == "") {
            api.toast({
                msg: '条码内容不匹配【物料】！',
                duration: 3000
            });
            return;
        }
        if (lotCode == null || lotCode == "") {
            api.toast({
                msg: '条码内容不匹配【批次】！',
                duration: 3000
            });
            return;
        }
        if (qqt == null || qqt == "" || parseFloat(qqt) <= 0) {
            api.toast({
                msg: '条码内容不匹配【数量】！',
                duration: 3000
            });
            return;
        }

        for (var i = 0; i < listData.length; i++) {
            console.log(i + "mrlCode", listData[i].mrl_code);
            console.log(i + "lotCode", listData[i].lot_code);
            if (listData[i].mrl_code == mrlCode && listData[i].lot_code == lotCode) {
                if (cellCode != null && cellCode != undefined && cellCode != "") {
                    if (listData[i].work_cell_code == cellCode.split(":")[0]) {
                        flag = true;
                        saveData(listData[i].sysid, qqt);
                    }
                } else {
                    flag = true;
                    saveData(listData[i].sysid, qqt);
                }
            }
        }
        if (!flag) {
            api.confirm({
                title: '提示',
                msg: '物料不在当前盘点单中，是否新增？',
                buttons: ['确定', '取消']
            }, function (ret, err) {
                if (ret.buttonIndex == 1) {
                    //新增物料必须选库位
                    if (cellCode == null || cellCode == "") {
                        api.toast({
                            msg: '请选择库位',
                            duration: 3000
                        });
                        return;
                    }
                    var un = localStorage.getItem('un');
                    var data = {
                        values: {
                            un: un,
                            workCellCode: cellCode.split(":")[0],
                            mrlCode: mrlCode,
                            lotCode: lotCode,
                            qty: qqt,
                            sysid: listData[0].sysid

                        }
                    };
                    addData(data);
                } else {
                    $("#codeBar").val("");
                    $("#codeBar").focus();
                    idSelector = "codeBar";
                }
            });

        }

    }

    function addData(data) {
        api.showProgress({
            title: '保存中...',
        });
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/wminventorybillDetailAdd";
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    //清空表单
                    $("#codeBar").val("");
                    $("#codeBar").select();
                    idSelector = "codeBar";
                    doSearch(api.pageParam.sysid);

                } else if (myobj.code == '1') {
                    $("#codeBar").val("");
                    api.hideProgress();
                    $("#codeBar").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }else{
                $("#codeBar").val("");
                $("#codeBar").select();
                idSelector = "codeBar";
                api.hideProgress();
                alert("连接超时，请耐心等待");
            }
        });
    }

    function saveData(sysid, qty) {
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/wminventorybillDetailSave";
        var data = {
            values: {
                un: un,
                sysid: sysid,
                qty: qty
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    //清空表单
                    $("#codeBar").val("");
                    doSearch(api.pageParam.sysid);

                } else if (myobj.code == '1') {
                    $("#codeBar").val("");
                    api.hideProgress();
                    $("#codeBar").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>